package com.api.weavernorth.action.breastFeeding;

import com.weavernorth.action.breastFeeding.BreastFeeding;
import com.weavernorth.util.Logger4jUtil;
import net.sf.json.JSONObject;
import org.apache.log4j.Logger;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;

/**
 * @Author: BruseeWang
 * @Date: 2020/12/30 14:57
 * @Description: 根据日期范围生成每一天的哺乳假流程
 */
@Path("/weavernorth/action/breast")
public class IbreastFeeding {
    private Logger log = Logger4jUtil.getLoggerByName("/Timmer/BreastFeeding/");
    @GET
    @Path("/getBreast")
    @Produces(MediaType.TEXT_PLAIN)
    public String execute(@Context HttpServletRequest request, @Context HttpServletResponse response){
        log.info("哺乳假日期范围内生成==>：");
        String strResult="哺乳假生成成功!";
        try {
            String userid = request.getParameter("userid");
            log.info("人员id:"+userid);
            String beginDates = request.getParameter("beginDates");
            log.info("开始日期:"+beginDates);
            String endDates = request.getParameter("endDates");
            log.info("结束日期:"+endDates);
            if(beginDates!=null&&endDates!=null){
                BreastFeeding breastFeeding = new BreastFeeding();
                strResult = breastFeeding.breastExecute(beginDates, endDates, userid);
                log.info(strResult);
            }else{
                strResult="请选择日期范围！";
            }
            return strResult;
        }catch (Exception ex){
            strResult="哺乳假生成失败,失败原因："+ex.toString();
            return strResult;
        }finally {
            JSONObject result_json=new JSONObject();
            result_json.put("msg",strResult);
            return result_json.toString();
        }

    }

}
